package com.cainaer.product.controller;


import com.cainaer.common.core.utils.StringUtils;
import com.cainaer.common.core.web.controller.BaseController;
import com.cainaer.common.core.web.domain.AjaxResult;
import com.cainaer.product.domain.ProductSku;
import com.cainaer.product.service.IProductSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * SKU表 前端控制器
 * </p>
 *
 * @author Tina
 * @since 2020-09-11
 */
@RestController
@RequestMapping("/productSku/")
public class ProductSkuController extends BaseController {

    @Autowired
    private IProductSkuService productSkuService;


    /**
     * 通过规格ID查询Sku数据
     *
     * @param attributeId
     * @return
     */
    @GetMapping("selectSystemAttributeById/{attributeId}")
    public AjaxResult selectSystemAttributeById(@PathVariable Long attributeId) {
        if (StringUtils.isNull(attributeId)) {
            return AjaxResult.error("主键不能为空");
        }
        return AjaxResult.success(productSkuService.selectProductSkuByAttributeId(attributeId));
    }


    /**
     * 新增 sku
     *
     * @param productSku
     * @return
     */
    @PostMapping("add")
    public AjaxResult add(ProductSku productSku) {
        return toAjax(productSkuService.insertProductSku(productSku));
    }

    /**
     * 编辑sku
     *
     * @param productSku
     * @return
     */
    @PostMapping("edit")
    public AjaxResult edit(ProductSku productSku) {
        return toAjax(productSkuService.editProductSku(productSku));
    }


}
